package org.ezplatform.office.questionnaire.dao;
 
import org.ezplatform.core.dao.jpa.JpaBaseDao;
import org.ezplatform.office.questionnaire.entity.QuestionnaireAnswer;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("questionnaireAnswerDao")
public interface QuestionnaireAnswerDao extends JpaBaseDao<QuestionnaireAnswer,String>{
	
	@Query("from QuestionnaireAnswer  where   userId = ?1 and optionId=?2 ")
	QuestionnaireAnswer getAnswerInfo(String userId,String optionId);
	
	@Query("from QuestionnaireAnswer  where   userId = ?1 and optionId in (?2)")
	List<QuestionnaireAnswer> getAnswerInfoByOptions(String userId,List<String> optionIds);
	
	@Query("from QuestionnaireAnswer  where   userId = ?1 and topicId = ?2 and optionId=?3 ")
	QuestionnaireAnswer getAnswerInfoByTopId(String userId,String topId,String optionId);

	@Modifying
	@Query(nativeQuery = true, value = "delete from oa_questionnaire_answer where user_id =?1 and questionnaire_id =?2")
	int deleteAnswerByQuesId(String userId,String quesId);
	
	@Modifying
	@Query(nativeQuery = true, value = "delete from oa_questionnaire_answer where questionnaire_id =?1 ")
	int deleteAnswerByQuesId(String id);
	
	@Modifying
	@Query(nativeQuery = true, value = "delete from oa_questionnaire_answer where questionnaire_id in (?1)")
	int deleteAnswerByQuesId(List<String> list);

	@Query("from QuestionnaireAnswer  where  questionnaireId = ?1 ")
	List<QuestionnaireAnswer> getAnswerByQuesId(String quesId);
}
